﻿using System;
using System.Collections.Generic;
using System.Dynamic;
using System.IO;
using System.Linq;
using System.Text;
using Xunit;

namespace Windy.Json
{
    public class JsonDomTest
    {
        [Fact()]
        public void ObjectTest()
        {
            var json = "{\"intNum\":123,\"floatNum\":12.3,\"text\":\"Test, String!\",\"emptyArray\":[]}";

            var dom = json.ParseAsJson().ToDom();

            Assert.Equal(123m, dom.intNum);
            Assert.Equal(12.3m, dom.floatNum);
            Assert.Equal("Test, String!", dom.text);
            Assert.IsType<List<dynamic>>(dom.emptyArray);
            Assert.Empty(dom.emptyArray);
        }

        [Fact()]
        public void ArrayTest()
        {
            var json = "[\"abc\",123,123.3,{}]";
            var dom = json.ParseAsJson().ToDom().ToArray();
            dynamic[] expected = new dynamic[] { "abc", 123m, 123.3m, new ExpandoObject() };

            Assert.Equal(expected, dom);
        }
    }
}